@echo off

REM Substitute `notepad2' for the Windows `NOTEPAD'
REM Copyright (C) 2009, 2010, 2011, zeroxia[at]gmail[dot]com
REM All Rights Reserver.

setlocal EnableDelayedExpansion

set notepad2_exe=.\notepad.exe
set notepad2_ini=.\notepad2.ini
set target_exe=NOTEPAD.EXE

REM Make sure the new EXE is available
if not exist "!notepad2_exe!" (
	echo ERROR: !notepad2_exe!: not exists
	exit /b -1
)

REM Possible places where the Windows original NOTEPAD
REM might resides (The following lines, i.e., lines tarting with
REM "REM ; ", will be parsed as the target places for doing
REM the substitution):
REM ; "!WINDIR!\$NtServicePackUninstall$"
REM ; "!WINDIR!\LastGood"
REM ; "!WINDIR!\LastGood\system32"
REM ; "!WINDIR!\ServicePackFiles\i386"
REM ; "!WINDIR!\system32\dllcache"
REM ; "!WINDIR!\system32"
REM ; "!WINDIR!"

for /F "tokens=1-3" %%i in (%0) do (
	if %%i == REM if "%%j" == ";" (
		echo Checking: %%k
		if exist "%%k" (
			echo --^> Installing ^(possibly overwritting^):
			copy /y "!notepad2_exe!" "%%k\!target_exe!"
		) else (
			echo --^> Skipped
		)
	)
)

REM Finally, install the customized configuration file if available
if exist "!notepad2_ini!" (
	echo.
	echo ------------------------
	echo Installing !notepad2_ini!:
	copy /y "!notepad2_ini!" "!WINDIR!"
)

echo DONE

endlocal
